*------------------------------------------------------------------------------*
			*** CREATE DATASET WITH WIND DIRECTION IVs ***
*------------------------------------------------------------------------------*

use "${rawdata}wind/data_kreis_DWD_wind_d_20002019.dta", clear

*------------------------------------------------------------------------------*

***Prepare data
destring krs_id, gen(kreis_code)

gen rb = floor(kreis_code/100)

rename date election_date
rename wind_dir_mindist wind_dir_daily

recode wind_dir_daily ///
(0/90=1 "NE") (90/180=2 "SE") (180/270=3 "SW") (270/360=4 "NW"), gen(wind_dir_daily_q4)  

*------------------------------------------------------------------------------*

***Generate wind direction IVs
levelsof rb, local(regions) clean

foreach d in 1 2 4 {
	foreach r of local regions {
		gen iv_rb`r'_d`d' = (wind_dir_daily_q4==`d') * (rb==`r')
	} // r
} // d

*------------------------------------------------------------------------------*

***Save
qui compress

save "${tempdata}wind_rb_d_20002019_iv.dta", replace

*------------------------------------------------------------------------------*

clear

exit
